<template>
    <div>
        <Upload
                :before-upload="handleUpload"
                :action="uploadFileUrl">
            <Button icon="ios-cloud-upload-outline">上传文件</Button>
        </Upload>
        <div v-if="file !== null">上传文件: {{ file.name }} <Button type="text" @click="upload" :loading="loadingStatus">{{ loadingStatus ? 'Uploading' : '' }}</Button>

        </div>
    </div>
</template>

<script>
    import {

        //NewUpload,
        systemUpload,
        systemUploadFile,
        fileUpload

    } from "@/api/index";
    import axios from 'axios';
    export default {
        name: "uploadfileForlink",
        data () {
            return {
                formData: {
                    file: null,
                    title: "",
                    department:"",
                },
                mes:"上传失败",
                file: null,
                loadingStatus: false,
                uploadFileUrl: fileUpload,
                editSubsystemNews: {
                    title: "",
                    url: "",
                    department: "",
                },
            }
        },
        methods: {
            info (item) {
                this.$Message.info(item);
            },
            handleUpload (file) {
                this.file = file;
                return false;
            },
            upload () {
                this.loadingStatus = true;

                this.upSubmit();
              /*  setTimeout(() => {
                    this.file = null;
                    this.loadingStatus = false;
                    this.$Message.success('Success')
                }, 1500);*/
            },

            upSubmit (data) {
                if(this.file!==null){
                this.editSubsystemNews=data;

                let formData1 = new FormData();
                formData1.append("file", this.file);
                formData1.append("title",this.editSubsystemNews.title);
                formData1.append("department",this.editSubsystemNews.department);
                axios.post(this.uploadFileUrl, formData1)
                    .then(response => {
                        this.mes=response.message;

                        this.info(this.mes);
                        if(response.code=200){
                            this.$emit("func",false);
                        }
                    });


                    /*this.formData.file=this.file;
                    this.formData.title=this.editSubsystemNews.title;
                    this.formData.department=this.editSubsystemNews.department;
                    systemUploadFile(this.formData).then(res => {
                        this.loading = false;
                        if (res.success == true) {
                            this.mes=res.message;

                            this.info(this.mes);
                        }
                    });*/

                this.$emit("func",this.editSubsystemNews.title);
                this.file=null;
                }else{
                    this.info("请先上传文件");
                }
            }
        }
    }
</script>
<style scoped>

</style>
